﻿/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 

*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OSISToolTip;
using OSISFunction;
using OSISDynamicTranslation;
using OpenSISInstall;
using OpenSIS.OpenSISWCFServiceReference;
using System.Globalization;
using System.Web.UI.HtmlControls;

    public partial class MarkingPeriods : System.Web.UI.Page
    {
        TooltipLang TTL = new TooltipLang();
        protected string sCulture;

        protected void Page_Load(object sender, EventArgs e)
        {
            SISInstall SISInstall = new SISInstall();
            OpenSISWCFServiceSchoolDetailsClient schoolAdd = new OpenSISWCFServiceSchoolDetailsClient();
            OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
            DataTable dtDateFormat = InstallBL.getdateformat();
            if (dtDateFormat.Rows.Count > 0)
            {
                SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
            }
            CalExtStartDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            CalExtEndDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            CalExtGPBegins.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            CalExtGPEnds.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            CalExtBeginsEdit.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            CalExtEndsEdit.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            CalExtGPBeginsEdit.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            CalExtGPEndsEdit.Format = SISInstall.CalenderDateFormat.ToString().Trim();
            hdns.Value = sCulture;
            //ibtnAdd.Attributes.Add("onmouseover", "toolTip('Add')");
            //ibtnAdd.Attributes.Add("onmouseout", "toolTip()");
            //ibtnEdit.Attributes.Add("onmouseover", "toolTip('Edit')");
            //ibtnEdit.Attributes.Add("onmouseout", "toolTip()");
            //ibtnEdit.Attributes.Add("onclick", "toolTip('');return true;");
            //ibtnDelete.Attributes.Add("onmouseover", "toolTip('Delete')");
            //ibtnDelete.Attributes.Add("onmouseout", "toolTip()");
            //ibtnDelete.Attributes.Add("onclick", "toolTip('');return true;");
            try
            {
                if (!Page.IsPostBack)
                {
                   PopulateFullYear();
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                schoolAdd.Close();
                InstallBL.Close();
            }
        } 

        protected void btnEdit_Click(object sender, EventArgs e)
        {

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

        protected void btnCancelEdit_Click(object sender, EventArgs e)
        {
            ModalPopupExtender2.Enabled = false;
            PopulateFullYear();
        }

        protected void EditMarkingPeriod()
        {
            OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
            string MPStartDate = txtBeginsEdit.Text.ToString();
            string MPEndDate = txtEndsEdit.Text.ToString();

            //if (Page.Culture == "Arabic (Saudi Arabia)")
            //{
            //    MPBL.MPStartDate = DateTime.Parse(txtBeginsEdit.Text, new CultureInfo("ar-sa")).ToString(SISInstall.CalenderDateFormat, new CultureInfo("en-gb"));
            //    MPBL.MPEndDate = DateTime.Parse(txtEndsEdit.Text, new CultureInfo("ar-sa")).ToString(SISInstall.CalenderDateFormat, new CultureInfo("en-gb"));
            //}

            int SchId = Convert.ToInt32(Session["SchoolID"]);
            if (hdnschyrid.Value != null && hdnMarkingPeriodId.Value != null)
            {
                int SchyrId = Convert.ToInt32(hdnschyrid.Value);
                int MarkingPeriodId = Convert.ToInt32(hdnMarkingPeriodId.Value);
                DateTime beginyr = Convert.ToDateTime(MPStartDate, DateTimeFormatInfo.InvariantInfo);
                string beginyear = beginyr.Year.ToString();
                DateTime endyr = Convert.ToDateTime(MPEndDate, DateTimeFormatInfo.InvariantInfo);
                string endyear = endyr.Year.ToString();
                string SchyrName = beginyear + "-" + endyear;

                string gradeind = "";
                if (chkGradeEdit.Checked)
                {
                    gradeind = "Y";
                }
                else
                {
                    gradeind = "N";
                }
                string MPGradeInd = gradeind;
                string MPGrdStartDate = txtGPBeginsEdit.Text.ToString();
                string MPGrdEndDate = txtGPEndsEdit.Text.ToString();
                string MarkingPeriodName = txtTitleEdit.Text.ToString();
                string MPShortName = txtShortNameEdit.Text.ToString();
                MPStartDate = txtBeginsEdit.Text.ToString();
                string LastUpdate = DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo);
                MPBL.UpdateMarkingPeriod(MPStartDate, MPEndDate, LastUpdate, SchyrName, SchyrId, MPGradeInd, MPGrdStartDate, MPGrdEndDate, MarkingPeriodName, MPShortName, MarkingPeriodId);
                MPBL.Close();
            }
        }

        protected void PopulateUpdatedMP(int SchId, int SchyrId)
        {
            //MarkingPeriodBL MPBL = new MarkingPeriodBL();
            //DataTable dt = MPBL.PopulateMPAfterUpdate(SchId, SchyrId);
            //if (dt.Rows.Count > 0)            
            //{
            //    lblTitle.Text = dt.Rows[0]["sch_mp_name"].ToString();
            //    lblShortName.Text = dt.Rows[0]["sch_mp_short_nm"].ToString();
            //    DateTime tempB = Convert.ToDateTime(dt.Rows[0]["sch_mp_start_date"].ToString());
            //    DateTime tempE = Convert.ToDateTime(dt.Rows[0]["sch_mp_end_date"].ToString());
            //    lblBegins.Text = tempB.ToString("MM/dd/yyyy");
            //    lblEnds.Text = tempE.ToString("MM/dd/yyyy");
            //    DateTime tempGB = Convert.ToDateTime(dt.Rows[0]["sch_mp_grd_start_date"].ToString());
            //    DateTime tempGE = Convert.ToDateTime(dt.Rows[0]["sch_mp_grd_end_date"].ToString());
            //    lblGPBegins.Text = tempGB.ToString("MM/dd/yyyy");
            //    lblGPEnds.Text = tempGE.ToString("MM/dd/yyyy");
            //    if (dt.Rows[0]["sch_mp_grading_ind"].ToString() == "Y")
            //    {
            //        ChkGradeview.Checked = true;
            //        ChkGradeview.Enabled = false;
            //    }
            //    else
            //    {
            //        ChkGradeview.Checked = false;
            //    }
            //}
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            EditMarkingPeriod();
            PopulateFullYear();
            ModalPopupExtender2.Enabled = false;
        }

        protected void PopulateAllMarkingPeriod(string MPType)
        {
            //MarkingPeriodBL MPBL = new MarkingPeriodBL();
            //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            //MPBL.SchId = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
            //MPBL.SchyrId = Convert.ToInt32(Session["SchyrId"]);
            //MPBL.MarkingPeriodType = MPType;
            //DataTable dt = MPBL.PopulateAllMPDetails();
            //if (dt.Rows.Count > 0)
            //{
            //    lblTitle.Text = dt.Rows[0]["sch_mp_name"].ToString();
            //    lblShortName.Text = dt.Rows[0]["sch_mp_short_nm"].ToString();
            //    DateTime tempB = Convert.ToDateTime(dt.Rows[0]["sch_mp_start_date"].ToString());
            //    DateTime tempE = Convert.ToDateTime(dt.Rows[0]["sch_mp_end_date"].ToString());
            //    lblBegins.Text = tempB.ToString("MM/dd/yyyy");
            //    lblEnds.Text = tempE.ToString("MM/dd/yyyy");
            //    DateTime tempGB = Convert.ToDateTime(dt.Rows[0]["sch_mp_grd_start_date"].ToString());
            //    DateTime tempGE = Convert.ToDateTime(dt.Rows[0]["sch_mp_grd_end_date"].ToString());
            //    lblGPBegins.Text = tempGB.ToString("MM/dd/yyyy");
            //    lblGPEnds.Text = tempGE.ToString("MM/dd/yyyy");
            //    if (dt.Rows[0]["sch_mp_grading_ind"].ToString() == "Y")
            //    {
            //        ChkGradeview.Checked = true;
            //        ChkGradeview.Enabled = false;
            //    }
            //    else
            //    {
            //        ChkGradeview.Checked = false;
            //    }
            //}
        }

        protected void ibtnAdd_Click(object sender, ImageClickEventArgs e)
        {

        }

        protected void AddSemester()
        {
            OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
            int SchId = Convert.ToInt32(Session["SchoolID"]);
            int SchyrPrevYear = 2008;
            int SchyrNextYear = 2009;
            string MPStartDate = txtBegins.Text.ToString();
            string MPEndDate = txtEnds.Text.ToString();
            int SchyrYear = Convert.ToInt32(hdnschyrid.Value);
            string SchyrShortName = "";
            string SchyrName = "";
            DataTable dt = MPBL.PopulateSchoolYearName(SchId);
            if (dt.Rows.Count > 0)
            {
                SchyrShortName = dt.Rows[0]["schyr_short_nm"].ToString();
                SchyrName = dt.Rows[0]["schyr_nm"].ToString();
            }
            string MarkingPeriodType = "S";
            int YearTypeId = MPBL.ReturnMarkingPeriodTypeId(MarkingPeriodType);
            string LastUpdate = DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo);
            int SchyrId = MPBL.InsertintoSchoolYear(MPStartDate, MPEndDate, SchyrShortName, SchyrName, SchyrYear, LastUpdate, SchyrNextYear, SchyrPrevYear, YearTypeId);
            MPStartDate = txtBegins.Text.ToString();
            MPEndDate = txtEnds.Text.ToString();
            string gradeind = "";
            string MPAttendenceInd = "N";
            if (chkGrade.Checked)
            {
                gradeind = "Y";
            }
            else
            {
                gradeind = "N";
            }
            string MPGradeInd = gradeind;
            string MPGrdStartDate = txtGPBegins.Text.ToString();
            string MPGrdEndDate = txtGPEnds.Text.ToString();
            string MarkingPeriodName = txtTitle.Text.ToString();
            string MPShortName = txtShortName.Text.ToString();
            LastUpdate = DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo);
            MPBL.InsertintoMarkingPeriod(MarkingPeriodType, MPStartDate, MPEndDate, MPAttendenceInd, MPGradeInd, MPGrdStartDate, MPGrdEndDate, SchId, SchyrId, MarkingPeriodName, MPShortName, LastUpdate);
            MPBL.Close();
        }

        protected void AddQuarter()
        {
            OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
            int SchId = Convert.ToInt32(Session["SchoolID"]);
            int SchyrPrevYear = 2008;
            int SchyrNextYear = 2009;
            string MPStartDate = txtBegins.Text.ToString();
            string MPEndDate = txtEnds.Text.ToString();
            int SchyrYear = Convert.ToInt32(hdnschyrid.Value);
            string SchyrShortName = "";
            string SchyrName = "";
            DataTable dt = MPBL.PopulateSchoolYearName(SchId);
            if (dt.Rows.Count > 0)
            {
                SchyrShortName = dt.Rows[0]["schyr_short_nm"].ToString();
                SchyrName = dt.Rows[0]["schyr_nm"].ToString();
            }
            string MarkingPeriodType = "Q";
            int YearTypeId = MPBL.ReturnMarkingPeriodTypeId(MarkingPeriodType);
            string LastUpdate = DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo);
            int SchyrId = MPBL.InsertintoSchoolYear(MPStartDate, MPEndDate, SchyrShortName, SchyrName, SchyrYear, LastUpdate, SchyrNextYear, SchyrPrevYear, YearTypeId);
            MPStartDate = txtBegins.Text.ToString();
            MPEndDate = txtEnds.Text.ToString();
            string gradeind = "";
            string MPAttendenceInd = "N";
            if (chkGrade.Checked)
            {
                gradeind = "Y";
            }
            else
            {
                gradeind = "N";
            }
            string MPGradeInd = gradeind;
            string MPGrdStartDate = txtGPBegins.Text.ToString();
            string MPGrdEndDate = txtGPEnds.Text.ToString();
            string MarkingPeriodName = txtTitle.Text.ToString();
            string MPShortName = txtShortName.Text.ToString();
            LastUpdate = DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo);
            MPBL.InsertintoMarkingPeriod(MarkingPeriodType, MPStartDate, MPEndDate, MPAttendenceInd, MPGradeInd, MPGrdStartDate, MPGrdEndDate, SchId, SchyrId, MarkingPeriodName, MPShortName, LastUpdate);
            MPBL.Close();
        }

        protected void AddProgressPeriod()
        {
            OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
            int SchId = Convert.ToInt32(Session["SchoolID"]);
            int SchyrPrevYear = 2008;
            int SchyrNextYear = 2009;
            string MPStartDate = txtBegins.Text.ToString();
            string MPEndDate = txtEnds.Text.ToString();
            int SchyrYear = Convert.ToInt32(hdnschyrid.Value);
            string SchyrShortName = "";
            string SchyrName = "";
            DataTable dt = MPBL.PopulateSchoolYearName(SchId);
            if (dt.Rows.Count > 0)
            {
                SchyrShortName = dt.Rows[0]["schyr_short_nm"].ToString();
                SchyrName = dt.Rows[0]["schyr_nm"].ToString();
            }
            string MarkingPeriodType = "P";
            int YearTypeId = MPBL.ReturnMarkingPeriodTypeId(MarkingPeriodType);
            string LastUpdate = DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo);
            int SchyrId = MPBL.InsertintoSchoolYear(MPStartDate, MPEndDate, SchyrShortName, SchyrName, SchyrYear, LastUpdate, SchyrNextYear, SchyrPrevYear, YearTypeId);
            MPStartDate = txtBegins.Text.ToString();
            MPEndDate = txtEnds.Text.ToString();
            string gradeind = "";
            string MPAttendenceInd = "N";
            if (chkGrade.Checked)
            {
                gradeind = "Y";
            }
            else
            {
                gradeind = "N";
            }
            string MPGradeInd = gradeind;
            string MPGrdStartDate = txtGPBegins.Text.ToString();
            string MPGrdEndDate = txtGPEnds.Text.ToString();
            string MarkingPeriodName = txtTitle.Text.ToString();
            string MPShortName = txtShortName.Text.ToString();
            LastUpdate = DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo);
            MPBL.InsertintoMarkingPeriod(MarkingPeriodType, MPStartDate, MPEndDate, MPAttendenceInd, MPGradeInd, MPGrdStartDate, MPGrdEndDate, SchId, SchyrId, MarkingPeriodName, MPShortName, LastUpdate);
            MPBL.Close();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Function Func = new Function();
            try
            {
                if (hdnParentType.Value == "Y")
                {
                    AddSemester();
                    PopulateFullYear();
                }
                else if (hdnParentType.Value == "S")
                {
                    AddQuarter();
                    PopulateFullYear();
                }
                else
                {
                    AddProgressPeriod();
                    PopulateFullYear();
                }
            }
            catch
            {
            }
            finally
            {
                txtTitle.Text = "";
                txtShortName.Text = "";
                chkGrade.Checked = false;
                txtBegins.Text = "";
                txtEnds.Text = "";
                txtGPBegins.Text = "";
                txtGPEnds.Text = "";
            }
        }

        protected void ibtnDelete_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
                for (int i = 0; i < gvFullYear.Rows.Count; i++)
                {
                    HiddenField hdnSchyrId = (HiddenField)gvFullYear.Rows[i].FindControl("hdnSchyrId");
                    HiddenField hdnMPId = (HiddenField)gvFullYear.Rows[i].FindControl("hdnMPId");
                    CheckBox chkyear = (CheckBox)gvFullYear.Rows[i].FindControl("chk");
                    GridView gvLevel1 = (GridView)gvFullYear.Rows[i].FindControl("gvLevel1");
                    if (chkyear.Checked)
                    {
                        Session["SchyrId"] = hdnSchyrId.Value.ToString();
                        int SchyrIds = Convert.ToInt32(Session["SchyrId"]);
                        int MarkingPeriodId = Convert.ToInt32(hdnMPId.Value);
                        MPBL.DeleteMarkingPeriod(MarkingPeriodId, SchyrIds);
                        PopulateFullYear();
                        break;
                    }
                    else
                    {
                        for (int j = 0; j < gvLevel1.Rows.Count; j++)
                        {
                            HiddenField SchyrId = (HiddenField)gvLevel1.Rows[j].FindControl("hdnSchyrIdlevel1");
                            HiddenField MPIDS = (HiddenField)gvLevel1.Rows[j].FindControl("hdnMPIdlevel1");
                            CheckBox chksem = (CheckBox)gvLevel1.Rows[j].FindControl("chk");
                            GridView gvLevel2 = (GridView)gvLevel1.Rows[j].FindControl("gvLevel2");
                            if (chksem.Checked)
                            {
                                Session["SchyrId"] = SchyrId.Value.ToString();
                                int SchyrIds = Convert.ToInt32(Session["SchyrId"]);
                                int MarkingPeriodId = Convert.ToInt32(MPIDS.Value);
                                MPBL.DeleteMarkingPeriod(MarkingPeriodId, SchyrIds);
                                PopulateFullYear();
                                break;
                            }
                            else
                            {
                                for (int n = 0; n < gvLevel2.Rows.Count; n++)
                                {
                                    HiddenField SchrId = (HiddenField)gvLevel2.Rows[n].FindControl("hdnSchyrId");
                                    HiddenField MPIDQ = (HiddenField)gvLevel2.Rows[n].FindControl("hdnMPId");
                                    CheckBox chkQua = (CheckBox)gvLevel2.Rows[n].FindControl("chk");
                                    GridView gvLevel3 = (GridView)gvLevel2.Rows[n].FindControl("gvLevel3");
                                    Label lblLevel2 = (Label)gvLevel2.Rows[n].FindControl("lblLevel2");
                                    if (chkQua.Checked)
                                    {
                                        Session["SchyrId"] = SchrId.Value.ToString();
                                        int SchyrIds = Convert.ToInt32(Session["SchyrId"]);
                                        int MarkingPeriodId = Convert.ToInt32(MPIDQ.Value);
                                        MPBL.DeleteMarkingPeriod(MarkingPeriodId, SchyrIds);
                                        PopulateFullYear();
                                        break;
                                    }
                                    else
                                    {
                                        for (int m = 0; m < gvLevel3.Rows.Count; m++)
                                        {
                                            HiddenField SchrIdPP = (HiddenField)gvLevel3.Rows[m].FindControl("hdnSchyrId");
                                            HiddenField MPIDPP = (HiddenField)gvLevel3.Rows[m].FindControl("hdnMPId");
                                            CheckBox chkPP = (CheckBox)gvLevel3.Rows[m].FindControl("chk");
                                            Label lblLevel3 = (Label)gvLevel3.Rows[m].FindControl("lblLevel3");
                                            if (chkPP.Checked)
                                            {
                                                Session["SchyrId"] = SchrIdPP.Value.ToString();
                                                int SchyrIds = Convert.ToInt32(Session["SchyrId"]);
                                                int MarkingPeriodId = Convert.ToInt32(MPIDPP.Value);
                                                MPBL.DeleteMarkingPeriod(MarkingPeriodId, SchyrIds);
                                                PopulateFullYear();
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                MPBL.Close();
            }
            catch
            {
            }
        }

        protected void PopulateFullYear()
        {
            DataTable dt = new DataTable();
            OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
            int SchId = Convert.ToInt32(Session["SchoolID"]);
            dt = MPBL.PopulateMarkingPeriodDetails(SchId);
            gvFullYear.DataSource = dt;
            gvFullYear.DataBind();
            MPBL.Close();
        }

        protected void gvFullYear_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HiddenField hdnSchyrId = (HiddenField)e.Row.FindControl("hdnSchyrIdfullyear");
                HiddenField hdnChkGrade = (HiddenField)e.Row.FindControl("hdnChkGrade");
                CheckBox Chkgrade = (CheckBox)e.Row.FindControl("Chkgradefullyear");
                GridView gvLevel1 = (GridView)e.Row.FindControl("gvLevel1");
                int SchId = Convert.ToInt32(Session["SchoolID"]);
                //-------------------------------------------------------------------------------
                OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
                SISInstall SISInstall = new SISInstall();
                DataTable dtDateFormat = InstallBL.getdateformat();
                if (dtDateFormat.Rows.Count > 0)
                {
                    SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
                }
                Label lblBeginsDate = (Label)e.Row.FindControl("lblBeginsDate");
                Label lblEndDate = (Label)e.Row.FindControl("lblEndDate");
                Label lblGPBeginsDate = (Label)e.Row.FindControl("lblGPBeginsDate");
                Label lblGPEndDate = (Label)e.Row.FindControl("lblGPEndDate");
                DateTime BeginsDate = Convert.ToDateTime(lblBeginsDate.Text.ToString());
                DateTime EndDate = Convert.ToDateTime(lblEndDate.Text.ToString());
                DateTime GPBeginsDate = Convert.ToDateTime(lblGPBeginsDate.Text.ToString());
                DateTime GPEndDate = Convert.ToDateTime(lblGPEndDate.Text.ToString());
                lblBeginsDate.Text = BeginsDate.ToString(SISInstall.CalenderDateFormat);
                lblEndDate.Text = EndDate.ToString(SISInstall.CalenderDateFormat);
                if (GPBeginsDate.ToString("MM/dd/yyyy") == "01/01/1900")
                {
                    lblGPBeginsDate.Text = "";
                }
                else
                {
                    lblGPBeginsDate.Text = GPBeginsDate.ToString(SISInstall.CalenderDateFormat);
                }
                if (GPEndDate.ToString("MM/dd/yyyy") == "01/01/1900")
                {
                    lblGPEndDate.Text = "";
                }
                else
                {
                    lblGPEndDate.Text = GPEndDate.ToString(SISInstall.CalenderDateFormat);
                }
                //----------------------------------------------------------------------------------
                HtmlImage img = (HtmlImage)e.Row.FindControl("imgFullYear");
                HtmlTable table = (HtmlTable)e.Row.FindControl("tableFullYear");
                HtmlTable tableDetails = (HtmlTable)e.Row.FindControl("tableFullYearDetails");
                HtmlTable tableIcons = (HtmlTable)e.Row.FindControl("tableFullYearIcons");                
                img.Attributes.Add("onclick", "OpenCloseDiv('" + table.ClientID + "','" + tableDetails.ClientID + "','" + tableIcons.ClientID + "','" + img.ClientID + "');");  
                ImageButton ibtnAdd = (ImageButton)e.Row.FindControl("ibtnAdd");
                TTL.tooltip();
                ibtnAdd.Attributes.Add("onmouseover", "toolTip('" + TTL.Add + "')");
                ibtnAdd.Attributes.Add("onmouseout", "toolTip()");
                ibtnAdd.Attributes.Add("onclick", " toolTip('')");
                ImageButton ibtnEdit = (ImageButton)e.Row.FindControl("ibtnEdit");
                ibtnEdit.Attributes.Add("onmouseover", "toolTip('" + TTL.Edit + "')");
                ibtnEdit.Attributes.Add("onmouseout", "toolTip()");
                ibtnEdit.Attributes.Add("onclick", " toolTip('')");
                ImageButton ibtnDelete = (ImageButton)e.Row.FindControl("ibtnDelete");
                ibtnDelete.Attributes.Add("onmouseover", "toolTip('" + TTL.Delete + "')");
                ibtnDelete.Attributes.Add("onmouseout", "toolTip()");
                ibtnDelete.Attributes.Add("onclick", " toolTip('')");
                int SchyrId = Convert.ToInt32(hdnSchyrId.Value);
                string MarkingPeriodType = "S";
                DataTable dtSem = MPBL.PopulateMarkingPeriodAll(SchId, MarkingPeriodType, SchyrId);
                if (hdnChkGrade.Value.ToString() == "Y")
                {
                    Chkgrade.Checked = true;
                }
                else
                {
                    Chkgrade.Checked = false;
                }

                Page.RegisterStartupScript("Information", "<Script Language='JavaScript'>OpenCloseDiv('" + table.ClientID + "','" + tableDetails.ClientID + "','" + tableIcons.ClientID + "','" + img.ClientID + "');</Script>");

                if (dtSem.Rows.Count > 0)
                {
                    gvLevel1.DataSource = dtSem;
                    gvLevel1.DataBind();
                }
                InstallBL.Close();
            }           
            MPBL.Close();
        }

        protected void gvLevel1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HiddenField hdnSchyrId = (HiddenField)e.Row.FindControl("hdnSchyrIdlevel1");
                HiddenField hdnChkGrade = (HiddenField)e.Row.FindControl("hdnChkGradelevel1");
                CheckBox Chkgrade = (CheckBox)e.Row.FindControl("Chkgradelevel1");
                GridView gvLevel2 = (GridView)e.Row.FindControl("gvLevel2");
                HtmlImage img = (HtmlImage)e.Row.FindControl("imgLevel1");
                HtmlTable table = (HtmlTable)e.Row.FindControl("tableLevel1");
                HtmlTable tableDetails = (HtmlTable)e.Row.FindControl("tableLevel1Details");
                HtmlTable tableIcons = (HtmlTable)e.Row.FindControl("tableLevel1Icons");
                //------------------------------------------------------------------
                OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
                SISInstall SISInstall = new SISInstall();
                DataTable dtDateFormat = InstallBL.getdateformat();
                if (dtDateFormat.Rows.Count > 0)
                {
                    SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
                }
                Label lblBeginsDate = (Label)e.Row.FindControl("lblBeginsDatelevel1");
                Label lblEndDate = (Label)e.Row.FindControl("lblEndDatelevel1");
                Label lblGPBeginsDate = (Label)e.Row.FindControl("lblGPBeginsDatelevel1");
                Label lblGPEndDate = (Label)e.Row.FindControl("lblGPEndDatelevel1");
                DateTime BeginsDate = Convert.ToDateTime(lblBeginsDate.Text.ToString());
                DateTime EndDate = Convert.ToDateTime(lblEndDate.Text.ToString());
                DateTime GPBeginsDate = Convert.ToDateTime(lblGPBeginsDate.Text.ToString());
                DateTime GPEndDate = Convert.ToDateTime(lblGPEndDate.Text.ToString());
                lblBeginsDate.Text = BeginsDate.ToString(SISInstall.CalenderDateFormat);
                lblEndDate.Text = EndDate.ToString(SISInstall.CalenderDateFormat);
                if (GPBeginsDate.ToString("MM/dd/yyyy") == "01/01/1900")
                {
                    lblGPBeginsDate.Text = "";
                }
                else
                {
                    lblGPBeginsDate.Text = GPBeginsDate.ToString(SISInstall.CalenderDateFormat);
                }
                if (GPEndDate.ToString("MM/dd/yyyy") == "01/01/1900")
                {
                    lblGPEndDate.Text = "";
                }
                else
                {
                    lblGPEndDate.Text = GPEndDate.ToString(SISInstall.CalenderDateFormat);
                }
                //------------------------------------------------------------------
                img.Attributes.Add("onclick", "OpenCloseDiv('" + table.ClientID + "','" + tableDetails.ClientID + "','" + tableIcons.ClientID + "','" + img.ClientID + "');");
                TTL.tooltip();
                ImageButton ibtnAdd = (ImageButton)e.Row.FindControl("ibtnAddlevel1");
                ibtnAdd.Attributes.Add("onmouseover", "toolTip('" + TTL.Add + "')");
                ibtnAdd.Attributes.Add("onmouseout", "toolTip()");
                ibtnAdd.Attributes.Add("onclick", " toolTip('')");
                ImageButton ibtnEdit = (ImageButton)e.Row.FindControl("ibtnEditlevel1");
                ibtnEdit.Attributes.Add("onmouseover", "toolTip('" + TTL.Edit + "')");
                ibtnEdit.Attributes.Add("onmouseout", "toolTip()");
                ibtnEdit.Attributes.Add("onclick", " toolTip('')");
                ImageButton ibtnDelete = (ImageButton)e.Row.FindControl("ibtnDeletelevel1");
                ibtnDelete.Attributes.Add("onmouseover", "toolTip('" + TTL.Delete + "')");
                ibtnDelete.Attributes.Add("onmouseout", "toolTip()");
                ibtnDelete.Attributes.Add("onclick", " toolTip('')");
                int SchId = Convert.ToInt32(Session["SchoolID"]);
                int SchyrId = Convert.ToInt32(hdnSchyrId.Value);
                string MarkingPeriodType = "Q";
                DataTable dtSem = MPBL.PopulateMarkingPeriodAll(SchId, MarkingPeriodType, SchyrId);
                if (hdnChkGrade.Value.ToString() == "Y")
                {
                    Chkgrade.Checked = true;
                }
                else
                {
                    Chkgrade.Checked = false;
                }              

                if (dtSem.Rows.Count > 0)
                { 
                    gvLevel2.DataSource = dtSem;
                    gvLevel2.DataBind();
                }                
                InstallBL.Close();
                Page.RegisterStartupScript("Information", "<Script Language='JavaScript'>OpenCloseDiv('" + table.ClientID + "','" + tableDetails.ClientID + "','" + tableIcons.ClientID + "','" + img.ClientID + "');</Script>");
                
            }
            MPBL.Close();
        }

        protected void gvLevel2_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HiddenField hdnSchyrId = (HiddenField)e.Row.FindControl("hdnSchyrIdlevel2");
                HiddenField hdnChkGrade = (HiddenField)e.Row.FindControl("hdnChkGradelevel2");
                CheckBox Chkgrade = (CheckBox)e.Row.FindControl("Chkgradelevel2");
                GridView gvLevel3 = (GridView)e.Row.FindControl("gvLevel3");
                HtmlImage img = (HtmlImage)e.Row.FindControl("imgLevel2");
                HtmlTable table = (HtmlTable)e.Row.FindControl("tableLevel2");
                HtmlTable tableDetails = (HtmlTable)e.Row.FindControl("tableLevel2Details");
                HtmlTable tableIcons = (HtmlTable)e.Row.FindControl("tableLevel2Icons");
                //------------------------------------------------------------------
                OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
                SISInstall SISInstall = new SISInstall();
                DataTable dtDateFormat = InstallBL.getdateformat();
                if (dtDateFormat.Rows.Count > 0)
                {
                    SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
                }
                Label lblBeginsDate = (Label)e.Row.FindControl("lblBeginsDatelevel2");
                Label lblEndDate = (Label)e.Row.FindControl("lblEndDatelevel2");
                Label lblGPBeginsDate = (Label)e.Row.FindControl("lblGPBeginsDatelevel2");
                Label lblGPEndDate = (Label)e.Row.FindControl("lblGPEndDatelevel2");
                DateTime BeginsDate = Convert.ToDateTime(lblBeginsDate.Text.ToString());
                DateTime EndDate = Convert.ToDateTime(lblEndDate.Text.ToString());
                DateTime GPBeginsDate = Convert.ToDateTime(lblGPBeginsDate.Text.ToString());
                DateTime GPEndDate = Convert.ToDateTime(lblGPEndDate.Text.ToString());
                lblBeginsDate.Text = BeginsDate.ToString(SISInstall.CalenderDateFormat);
                lblEndDate.Text = EndDate.ToString(SISInstall.CalenderDateFormat);
                if (GPBeginsDate.ToString("MM/dd/yyyy") == "01/01/1900")
                {
                    lblGPBeginsDate.Text = "";
                }
                else
                {
                    lblGPBeginsDate.Text = GPBeginsDate.ToString(SISInstall.CalenderDateFormat);
                }
                if (GPEndDate.ToString("MM/dd/yyyy") == "01/01/1900")
                {
                    lblGPEndDate.Text = "";
                }
                else
                {
                    lblGPEndDate.Text = GPEndDate.ToString(SISInstall.CalenderDateFormat);
                }
                //------------------------------------------------------------------
                img.Attributes.Add("onclick", "OpenCloseDiv('" + table.ClientID + "','" + tableDetails.ClientID + "','" + tableIcons.ClientID + "','" + img.ClientID + "');");
                ImageButton ibtnAdd = (ImageButton)e.Row.FindControl("ibtnAddlevel2");
                ibtnAdd.Attributes.Add("onmouseover", "toolTip('" + TTL.Add + "')");
                ibtnAdd.Attributes.Add("onmouseout", "toolTip()");
                ibtnAdd.Attributes.Add("onclick", " toolTip('')");                
                ImageButton ibtnEdit = (ImageButton)e.Row.FindControl("ibtnEditlevel2");
                ibtnEdit.Attributes.Add("onmouseover", "toolTip('" + TTL.Edit + "')");
                ibtnEdit.Attributes.Add("onmouseout", "toolTip()");
                ibtnEdit.Attributes.Add("onclick", " toolTip('')");
                ImageButton ibtnDelete = (ImageButton)e.Row.FindControl("ibtnDeletelevel2");
                ibtnDelete.Attributes.Add("onmouseover", "toolTip('" + TTL.Delete + "')");
                ibtnDelete.Attributes.Add("onmouseout", "toolTip()");
                ibtnDelete.Attributes.Add("onclick", " toolTip('')");
                int SchId = Convert.ToInt32(Session["SchoolID"]);
                int SchyrId = Convert.ToInt32(hdnSchyrId.Value);
                string MarkingPeriodType = "P";
                DataTable dtSem = MPBL.PopulateMarkingPeriodAll(SchId, MarkingPeriodType, SchyrId);
                if (hdnChkGrade.Value.ToString() == "Y")
                {
                    Chkgrade.Checked = true;
                }
                else
                {
                    Chkgrade.Checked = false;
                }

                Page.RegisterStartupScript("Information", "<Script Language='JavaScript'>OpenCloseDiv('" + table.ClientID + "','" + tableDetails.ClientID + "','" + tableIcons.ClientID + "','" + img.ClientID + "');</Script>");

                if (dtSem.Rows.Count > 0)
                {
                    gvLevel3.DataSource = dtSem;
                    gvLevel3.DataBind();
                }
                InstallBL.Close();
                
            }
            MPBL.Close();
        }

        protected void gvLevel3_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HiddenField hdnSchyrId = (HiddenField)e.Row.FindControl("hdnSchyrIdlevel3");
                HiddenField hdnChkGrade = (HiddenField)e.Row.FindControl("hdnChkGradelevel3");
                CheckBox Chkgrade = (CheckBox)e.Row.FindControl("Chkgradelevel3");
                HtmlImage img = (HtmlImage)e.Row.FindControl("imgLevel3");
                HtmlTable table = (HtmlTable)e.Row.FindControl("tableLevel3");
                HtmlTable tableIcons = (HtmlTable)e.Row.FindControl("tableLevel3Icons");
                //------------------------------------------------------------------
                OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
                SISInstall SISInstall = new SISInstall();
                DataTable dtDateFormat = InstallBL.getdateformat();
                if (dtDateFormat.Rows.Count > 0)
                {
                    SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
                }
                Label lblBeginsDate = (Label)e.Row.FindControl("lblBeginsDatelevel3");
                Label lblEndDate = (Label)e.Row.FindControl("lblEndDatelevel3");
                Label lblGPBeginsDate = (Label)e.Row.FindControl("lblGPBeginsDatelevel3");
                Label lblGPEndDate = (Label)e.Row.FindControl("lblGPEndDatelevel3");
                DateTime BeginsDate = Convert.ToDateTime(lblBeginsDate.Text.ToString());
                DateTime EndDate = Convert.ToDateTime(lblEndDate.Text.ToString());
                DateTime GPBeginsDate = Convert.ToDateTime(lblGPBeginsDate.Text.ToString());
                DateTime GPEndDate = Convert.ToDateTime(lblGPEndDate.Text.ToString());
                lblBeginsDate.Text = BeginsDate.ToString(SISInstall.CalenderDateFormat);
                lblEndDate.Text = EndDate.ToString(SISInstall.CalenderDateFormat);
                if (GPBeginsDate.ToString("MM/dd/yyyy") == "01/01/1900")
                {
                    lblGPBeginsDate.Text = "";
                }
                else
                {
                    lblGPBeginsDate.Text = GPBeginsDate.ToString(SISInstall.CalenderDateFormat);
                }
                if (GPEndDate.ToString("MM/dd/yyyy") == "01/01/1900")
                {
                    lblGPEndDate.Text = "";
                }
                else
                {
                    lblGPEndDate.Text = GPEndDate.ToString(SISInstall.CalenderDateFormat);
                }
                //------------------------------------------------------------------
                img.Attributes.Add("onclick", "OpenCloseDiv('" + table.ClientID + "','" + table.ClientID + "','" + tableIcons.ClientID + "','" + img.ClientID + "');");    
                ImageButton ibtnEdit = (ImageButton)e.Row.FindControl("ibtnEditlevel3");
                ibtnEdit.Attributes.Add("onmouseover", "toolTip('" + TTL.Edit + "')");
                ibtnEdit.Attributes.Add("onmouseout", "toolTip()");
                ibtnEdit.Attributes.Add("onclick", " toolTip('')");
                ImageButton ibtnDelete = (ImageButton)e.Row.FindControl("ibtnDeletelevel3");
                ibtnDelete.Attributes.Add("onmouseover", "toolTip('" + TTL.Delete + "')");
                ibtnDelete.Attributes.Add("onmouseout", "toolTip()");
                ibtnDelete.Attributes.Add("onclick", " toolTip('')");
                if (hdnChkGrade.Value.ToString() == "Y")
                {
                    Chkgrade.Checked = true;
                }
                else
                {
                    Chkgrade.Checked = false;
                }
                InstallBL.Close();
                Page.RegisterStartupScript("Information", "<Script Language='JavaScript'>OpenCloseDiv('" + table.ClientID + "','" + table.ClientID + "','" + tableIcons.ClientID + "','" + img.ClientID + "');</Script>");
            }
        }

        protected void ibtnEdit_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
                for (int i = 0; i < gvFullYear.Rows.Count; i++)
                {
                    HiddenField hdnSchyrId = (HiddenField)gvFullYear.Rows[i].FindControl("hdnSchyrId");
                    HiddenField hdnMPId = (HiddenField)gvFullYear.Rows[i].FindControl("hdnMPId");
                    CheckBox chkyear = (CheckBox)gvFullYear.Rows[i].FindControl("chk");
                    GridView gvLevel1 = (GridView)gvFullYear.Rows[i].FindControl("gvLevel1");
                    if (chkyear.Checked)
                    {
                        Session["SchyrIdForEdit"] = hdnSchyrId.Value.ToString();
                        int MarkingPeriodId = Convert.ToInt32(hdnMPId.Value);
                        Session["MarkingPIDForEdit"] = Convert.ToInt32(hdnMPId.Value);
                        Label lblSchMPName = (Label)gvFullYear.Rows[i].FindControl("lblSchMPName");
                        Label lblShortName = (Label)gvFullYear.Rows[i].FindControl("lblShortName");
                        Label lblBeginsDate = (Label)gvFullYear.Rows[i].FindControl("lblBeginsDate");
                        Label lblEndDate = (Label)gvFullYear.Rows[i].FindControl("lblEndDate");
                        Label lblGPBeginsDate = (Label)gvFullYear.Rows[i].FindControl("lblGPBeginsDate");
                        Label lblGPEndDate = (Label)gvFullYear.Rows[i].FindControl("lblGPEndDate");
                        HiddenField hdnChkGrade = (HiddenField)gvFullYear.Rows[i].FindControl("hdnChkGrade");
                        txtTitleEdit.Text = lblSchMPName.Text.ToString();
                        txtShortNameEdit.Text = lblShortName.Text.ToString();
                        if (hdnChkGrade.Value.ToString() == "Y")
                        {
                            chkGradeEdit.Checked = true;
                        }
                        else
                        {
                            chkGradeEdit.Checked = false;
                        }
                        txtBeginsEdit.Text = lblBeginsDate.Text.ToString();
                        txtEndsEdit.Text = lblEndDate.Text.ToString();
                        txtGPBeginsEdit.Text = lblGPBeginsDate.Text.ToString();
                        txtGPEndsEdit.Text = lblGPEndDate.Text.ToString();
                        break;
                    }
                    else
                    {
                        for (int j = 0; j < gvLevel1.Rows.Count; j++)
                        {
                            HiddenField SchyrId = (HiddenField)gvLevel1.Rows[j].FindControl("hdnSchyrId");
                            HiddenField MPIDS = (HiddenField)gvLevel1.Rows[j].FindControl("hdnMPId");
                            CheckBox chksem = (CheckBox)gvLevel1.Rows[j].FindControl("chk");
                            GridView gvLevel2 = (GridView)gvLevel1.Rows[j].FindControl("gvLevel2");
                            if (chksem.Checked)
                            {
                                Session["SchyrIdForEdit"] = SchyrId.Value.ToString();
                                int MarkingPeriodId = Convert.ToInt32(MPIDS.Value);
                                Session["MarkingPIDForEdit"] = Convert.ToInt32(MPIDS.Value);
                                Label lblSchMPName = (Label)gvLevel1.Rows[j].FindControl("lblSchMPName");
                                Label lblShortName = (Label)gvLevel1.Rows[j].FindControl("lblShortName");
                                Label lblBeginsDate = (Label)gvLevel1.Rows[j].FindControl("lblBeginsDate");
                                Label lblEndDate = (Label)gvLevel1.Rows[j].FindControl("lblEndDate");
                                Label lblGPBeginsDate = (Label)gvLevel1.Rows[j].FindControl("lblGPBeginsDate");
                                Label lblGPEndDate = (Label)gvLevel1.Rows[j].FindControl("lblGPEndDate");
                                HiddenField hdnChkGrade = (HiddenField)gvLevel1.Rows[j].FindControl("hdnChkGrade");
                                txtTitleEdit.Text = lblSchMPName.Text.ToString();
                                txtShortNameEdit.Text = lblShortName.Text.ToString();
                                if (hdnChkGrade.Value.ToString() == "Y")
                                {
                                    chkGradeEdit.Checked = true;
                                }
                                else
                                {
                                    chkGradeEdit.Checked = false;
                                }
                                txtBeginsEdit.Text = lblBeginsDate.Text.ToString();
                                txtEndsEdit.Text = lblEndDate.Text.ToString();
                                txtGPBeginsEdit.Text = lblGPBeginsDate.Text.ToString();
                                txtGPEndsEdit.Text = lblGPEndDate.Text.ToString();
                                break;
                            }
                            else
                            {
                                for (int n = 0; n < gvLevel2.Rows.Count; n++)
                                {
                                    HiddenField SchrId = (HiddenField)gvLevel2.Rows[n].FindControl("hdnSchyrId");
                                    HiddenField MPIDQ = (HiddenField)gvLevel2.Rows[n].FindControl("hdnMPId");
                                    CheckBox chkQua = (CheckBox)gvLevel2.Rows[n].FindControl("chk");
                                    Label lblLevel2 = (Label)gvLevel2.Rows[n].FindControl("lblLevel2");
                                    GridView gvLevel3 = (GridView)gvLevel2.Rows[n].FindControl("gvLevel3");

                                    if (chkQua.Checked)
                                    {
                                        Session["SchyrIdForEdit"] = SchrId.Value.ToString();
                                        int MarkingPeriodId = Convert.ToInt32(MPIDQ.Value);
                                        Session["MarkingPIDForEdit"] = Convert.ToInt32(MPIDQ.Value);
                                        Label lblSchMPName = (Label)gvLevel2.Rows[n].FindControl("lblSchMPName");
                                        Label lblShortName = (Label)gvLevel2.Rows[n].FindControl("lblShortName");
                                        Label lblBeginsDate = (Label)gvLevel2.Rows[n].FindControl("lblBeginsDate");
                                        Label lblEndDate = (Label)gvLevel2.Rows[n].FindControl("lblEndDate");
                                        Label lblGPBeginsDate = (Label)gvLevel2.Rows[n].FindControl("lblGPBeginsDate");
                                        Label lblGPEndDate = (Label)gvLevel2.Rows[n].FindControl("lblGPEndDate");
                                        HiddenField hdnChkGrade = (HiddenField)gvLevel2.Rows[n].FindControl("hdnChkGrade");
                                        txtTitleEdit.Text = lblSchMPName.Text.ToString();
                                        txtShortNameEdit.Text = lblShortName.Text.ToString();
                                        if (hdnChkGrade.Value.ToString() == "Y")
                                        {
                                            chkGradeEdit.Checked = true;
                                        }
                                        else
                                        {
                                            chkGradeEdit.Checked = false;
                                        }
                                        txtBeginsEdit.Text = lblBeginsDate.Text.ToString();
                                        txtEndsEdit.Text = lblEndDate.Text.ToString();
                                        txtGPBeginsEdit.Text = lblGPBeginsDate.Text.ToString();
                                        txtGPEndsEdit.Text = lblGPEndDate.Text.ToString();
                                        break;
                                    }
                                    else
                                    {
                                        for (int m = 0; m < gvLevel3.Rows.Count; m++)
                                        {
                                            HiddenField SchrIdPP = (HiddenField)gvLevel3.Rows[m].FindControl("hdnSchyrId");
                                            HiddenField MPIDPP = (HiddenField)gvLevel3.Rows[m].FindControl("hdnMPId");
                                            CheckBox chkPP = (CheckBox)gvLevel3.Rows[m].FindControl("chk");
                                            Label lblLevel3 = (Label)gvLevel3.Rows[m].FindControl("lblLevel3");
                                            if (chkPP.Checked)
                                            {
                                                Session["SchyrIdForEdit"] = SchrIdPP.Value.ToString();
                                                int MarkingPeriodId = Convert.ToInt32(MPIDPP.Value);
                                                Session["MarkingPIDForEdit"] = Convert.ToInt32(MPIDPP.Value);
                                                Label lblSchMPName = (Label)gvLevel3.Rows[m].FindControl("lblSchMPName");
                                                Label lblShortName = (Label)gvLevel3.Rows[m].FindControl("lblShortName");
                                                Label lblBeginsDate = (Label)gvLevel3.Rows[m].FindControl("lblBeginsDate");
                                                Label lblEndDate = (Label)gvLevel3.Rows[m].FindControl("lblEndDate");
                                                Label lblGPBeginsDate = (Label)gvLevel3.Rows[m].FindControl("lblGPBeginsDate");
                                                Label lblGPEndDate = (Label)gvLevel3.Rows[m].FindControl("lblGPEndDate");
                                                HiddenField hdnChkGrade = (HiddenField)gvLevel3.Rows[m].FindControl("hdnChkGrade");
                                                txtTitleEdit.Text = lblSchMPName.Text.ToString();
                                                txtShortNameEdit.Text = lblShortName.Text.ToString();
                                                if (hdnChkGrade.Value.ToString() == "Y")
                                                {
                                                    chkGradeEdit.Checked = true;
                                                }
                                                else
                                                {
                                                    chkGradeEdit.Checked = false;
                                                }
                                                txtBeginsEdit.Text = lblBeginsDate.Text.ToString();
                                                txtEndsEdit.Text = lblEndDate.Text.ToString();
                                                txtGPBeginsEdit.Text = lblGPBeginsDate.Text.ToString();
                                                txtGPEndsEdit.Text = lblGPEndDate.Text.ToString();
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                ModalPopupExtender2.Enabled = true;
                ModalPopupExtender2.Show();
                MPBL.Close();
            }
            catch
            {
            }
        }

        //protected void PopulateMasterDropdownFullYear()
        //{
        //    SchoolBL schoolAdd = new SchoolBL();
        //    try
        //    {
        //        //schoolAdd.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
        //        //ddlFullYear = (DropDownList)Page.Master.FindControl("ddlFullYear");
        //        //ddlFullYear.Items.Clear();
        //        //schoolAdd.PopulateFullYear(ref ddlFullYear);
        //        //ddlFullYear.SelectedIndexChanged += new EventHandler(ddlFullYear_SelectedIndexChanged);
        //        //ddlFullYear.AutoPostBack = true;

        //        schoolAdd.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
        //        ddlFullYear = (DropDownList)Page.Master.FindControl("ddlFullYear");
        //        ddlFullYear.Items.Clear();
        //        ddlLevel1 = (DropDownList)Page.Master.FindControl("ddlLevel1");
        //        ddlLevel1.Items.Clear();
        //        schoolAdd.PopulateFullYear(ref ddlFullYear, ref ddlLevel1);
        //        ddlFullYear.Style.Add("font-family", "Arial Unicode MS");
        //        ddlLevel1.Style.Add("font-family", "Arial Unicode MS");
        //        //ddlFullYear.SelectedIndex = 1;
        //        //ddlLevel1.SelectedIndex = 1;
        //    }
        //    catch
        //    {

        //    }
        //    finally
        //    {
        //        schoolAdd = null;
        //    }
        //}

        //protected void PopulateMasterDropdownLevel1()
        //{
        //    SchoolBL schoolAdd = new SchoolBL();
        //    try
        //    {
        //        schoolAdd.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
        //        schoolAdd.SchyrYear = Convert.ToInt32(ddlFullYear.SelectedItem.Value);
        //        ddlLevel1 = (DropDownList)Page.Master.FindControl("ddlLevel1");
        //        ddlLevel1.Items.Clear();
        //        schoolAdd.PopulateLevel1(ref ddlLevel1);
        //        ddlLevel1.Style.Add("font-family", "Arial Unicode MS");
        //        //ddlLevel1.SelectedIndexChanged += new EventHandler(ddlLevel1_SelectedIndexChanged);
        //        //ddlLevel1.AutoPostBack = true;
        //    }
        //    catch
        //    {

        //    }
        //    finally
        //    {
        //        schoolAdd = null;
        //    }
        //}
        //protected void Page_PreInit(object sender, EventArgs e)
        //{
        //    PopulateMasterDropdown();
        //    //PopulateMasterDropdownFullYear();
        //    //PopulateMasterDropdownLevel1();

        //}


        //protected void ddlFullYear_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    PopulateMasterDropdownLevel1();

        //}

        //protected void ddlLevel1_SelectedIndexChanged(object sender, EventArgs e)
        //{

        //}

        protected void gvFullYear_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
                if (e.CommandName == "EditFullYearRecords")
                {
                    ModalPopupExtender2.Enabled = true;
                    ModalPopupExtender2.Show();
                    string info = e.CommandArgument.ToString();
                    string[] arg = new string[2];
                    char[] splitter = { '_' };
                    arg = info.Split(splitter);
                    string markingperiodid = arg[0];
                    string SchyrId = arg[1];
                    hdnMarkingPeriodId.Value = markingperiodid;
                    hdnschyrid.Value = SchyrId;
                    int SchId = Convert.ToInt32(Session["SchoolID"]);
                    int MarkingPeriodId = Convert.ToInt32(markingperiodid);
                    int SchyrIdS = Convert.ToInt32(SchyrId);
                    DataTable dt = MPBL.Populatemarkingperiodforedit(MarkingPeriodId);
                    txtTitleEdit.Text = dt.Rows[0]["sch_mp_name"].ToString();
                    txtShortNameEdit.Text = dt.Rows[0]["sch_mp_short_nm"].ToString();
                    if (dt.Rows[0]["sch_mp_grading_ind"].ToString() == "Y")
                    {
                        chkGradeEdit.Checked = true;
                    }
                    else
                    {
                        chkGradeEdit.Checked = false;
                    }
                    OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
                    SISInstall SISInstall = new SISInstall();
                    DataTable dtDateFormat = InstallBL.getdateformat();
                    if (dtDateFormat.Rows.Count > 0)
                    {
                        SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
                    }
                    string sch_mp_start_date = (dt.Rows[0]["sch_mp_start_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpstartdate = Convert.ToDateTime(sch_mp_start_date);
                    txtBeginsEdit.Text = schmpstartdate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_end_date = (dt.Rows[0]["sch_mp_end_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpenddate = Convert.ToDateTime(sch_mp_end_date);
                    txtEndsEdit.Text = schmpenddate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_grd_start_date = (dt.Rows[0]["sch_mp_grd_start_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpgrdstartdate = Convert.ToDateTime(sch_mp_grd_start_date);
                    txtGPBeginsEdit.Text = schmpgrdstartdate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_grd_end_date = (dt.Rows[0]["sch_mp_grd_end_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpgrdenddate = Convert.ToDateTime(sch_mp_grd_end_date);
                    txtGPEndsEdit.Text = schmpgrdenddate.ToString(SISInstall.CalenderDateFormat);
                }
                if (e.CommandName == "AddSemester")
                {
                    ModalPopupExtender1.Enabled = true;
                    ModalPopupExtender1.Show();
                    string schyrid = e.CommandArgument.ToString();
                    hdnschyrid.Value = schyrid;
                    hdnParentType.Value = "Y";
                }
                if (e.CommandName == "DeleteFullYear")
                {
                    string info = e.CommandArgument.ToString();
                    string[] arg = new string[2];
                    char[] splitter = { '_' };
                    arg = info.Split(splitter);
                    string markingperiodid = arg[0];
                    string SchyrId = arg[1];
                    string markingprdname = arg[2];
                    int MarkingPeriodId = Convert.ToInt32(markingperiodid);
                    int SchyrIds = Convert.ToInt32(SchyrId);
                    DataTable dt = MPBL.getchildcount(SchyrIds);
                    if (dt.Rows.Count == 0)
                    {
                        MPBL.DeleteMarkingPeriod(MarkingPeriodId, SchyrIds);
                    }
                    else
                    {
                        string s = System.Web.HttpContext.Current.Session["MLCulture"].ToString();
                        switch (s)
                        {
                            case "en-US":
                                lblmsg.Text = "You cannot delete " + markingprdname + ".Other marking periods were found under it.";
                                break;
                            case "es-MX":
                                lblmsg.Text = "No se puede eliminar " + markingprdname + ".Otro marcado en los períodos que se encontraron bajo.";
                                break;
                            case "zh-CN":
                                lblmsg.Text = "您不能删除 " + markingprdname + ".其他  印记  期  是  创立  根据  它.";
                                break;
                            case "ja-JP":
                                lblmsg.Text = "あなたが削除することはできません " + markingprdname + ".その他のマークの下で発見された期間.";
                                break;
                            case "de-DE":
                                lblmsg.Text = "Sie können nicht gelöscht " + markingprdname + ".Andere Markierung Zeiten waren gefunden unter es.";
                                break;
                            case "ko-KR":
                                lblmsg.Text = "당신은 삭제할 수없습니다   " + markingprdname + ".기타 마킹 기간 그 아래를 발견했다.";
                                break;
                            case "fr-FR":
                                lblmsg.Text = "Vous ne pouvez pas supprimer " + markingprdname + ".Autres périodes de marquage ont été trouvés à ce titre.";
                                break;
                            case "it-IT":
                                lblmsg.Text = "Non è possibile eliminare  " + markingprdname + ".Altri periodi di marcatura sono stati trovati sotto di essa.";
                                break;
                            case "ru-RU":
                                lblmsg.Text = "Вы не можете удалить " + markingprdname + ".Другая маркировка периоды были найдены в соответствии с ней.";
                                break;
                            case "pt-BR":
                                lblmsg.Text = "Você não pode apagar " + markingprdname + ".Outros marcação períodos em que foram encontrados.";
                                break;
                            case "ar-SA":
                                lblmsg.Text = ".العلامات فترات أخرى تم العثور عليها في إطار." + markingprdname + "لا يمكنك حذف ";
                                break;
                        }
                        ModalPopupExtender3.Enabled = true;
                        ModalPopupExtender3.Show();                        
                    }
                    PopulateFullYear();
                }
                MPBL.Close();
            }
            catch 
            { 
            }
        }

        //private static void CreateMessageAlert(Page aspxPage, string strMessage, string strKey)
        //{
        //    string strScript = "<script language=JavaScript>alert('" + strMessage + "')</script>";

        //    if ((!aspxPage.ClientScript.IsStartupScriptRegistered(strKey)))
        //    {
        //        aspxPage.ClientScript.RegisterStartupScript(typeof(string), strKey, strScript);
        //    }
        //}

        protected void gvLevel1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
                if (e.CommandName == "EditSemesterRecords")
                {
                    ModalPopupExtender2.Enabled = true;
                    ModalPopupExtender2.Show();
                    OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
                    SISInstall SISInstall = new SISInstall();
                    DataTable dtDateFormat = InstallBL.getdateformat();
                    if (dtDateFormat.Rows.Count > 0)
                    {
                        SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
                    }
                    string info = e.CommandArgument.ToString();
                    string[] arg = new string[2];
                    char[] splitter = { '_' };
                    arg = info.Split(splitter);
                    string markingperiodid = arg[0];
                    string SchyrId = arg[1];
                    hdnMarkingPeriodId.Value = markingperiodid;
                    hdnschyrid.Value = SchyrId;
                    int SchId = Convert.ToInt32(Session["SchoolID"]);
                    int MarkingPeriodId = Convert.ToInt32(markingperiodid);
                    int SchyrIds = Convert.ToInt32(SchyrId);
                    string MarkingPeriodType = "S";
                    DataTable dt = MPBL.Populatemarkingperiodforedit(MarkingPeriodId);
                    txtTitleEdit.Text = dt.Rows[0]["sch_mp_name"].ToString();
                    txtShortNameEdit.Text = dt.Rows[0]["sch_mp_short_nm"].ToString();
                    if (dt.Rows[0]["sch_mp_grading_ind"].ToString() == "Y")
                    {
                        chkGradeEdit.Checked = true;
                    }
                    else
                    {
                        chkGradeEdit.Checked = false;
                    }
                    string sch_mp_start_date = (dt.Rows[0]["sch_mp_start_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpstartdate = Convert.ToDateTime(sch_mp_start_date);
                    txtBeginsEdit.Text = schmpstartdate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_end_date = (dt.Rows[0]["sch_mp_end_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpenddate = Convert.ToDateTime(sch_mp_end_date);
                    txtEndsEdit.Text = schmpenddate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_grd_start_date = (dt.Rows[0]["sch_mp_grd_start_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpgrdstartdate = Convert.ToDateTime(sch_mp_grd_start_date);
                    txtGPBeginsEdit.Text = schmpgrdstartdate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_grd_end_date = (dt.Rows[0]["sch_mp_grd_end_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpgrdenddate = Convert.ToDateTime(sch_mp_grd_end_date);
                    txtGPEndsEdit.Text = schmpgrdenddate.ToString(SISInstall.CalenderDateFormat);
                    InstallBL.Close();
                }
                if (e.CommandName == "AddQuarter")
                {
                    ModalPopupExtender1.Enabled = true;
                    ModalPopupExtender1.Show();
                    string schyrid = e.CommandArgument.ToString();
                    hdnschyrid.Value = schyrid;
                    hdnParentType.Value = "S";
                }
                if (e.CommandName == "DeleteSemester")
                {
                    string info = e.CommandArgument.ToString();
                    string[] arg = new string[2];
                    char[] splitter = { '_' };
                    arg = info.Split(splitter);
                    string markingperiodid = arg[0];
                    string SchyrId = arg[1];
                    string markingprdname = arg[2];
                    int MarkingPeriodId = Convert.ToInt32(markingperiodid);
                    int SchyrIds = Convert.ToInt32(SchyrId);
                    DataTable dt = MPBL.getchildcount(SchyrIds);
                    if (dt.Rows.Count == 0)
                    {
                        MPBL.DeleteMarkingPeriod(MarkingPeriodId, SchyrIds);
                    }
                    else
                    {
                        string s = System.Web.HttpContext.Current.Session["MLCulture"].ToString();
                        switch (s)
                        {
                            case "en-US":
                                lblmsg.Text = "You cannot delete " + markingprdname + ".Other marking periods were found under it.";
                                break;
                            case "es-MX":
                                lblmsg.Text = "No se puede eliminar " + markingprdname + ".Otro marcado en los períodos que se encontraron bajo.";
                                break;
                            case "zh-CN":
                                lblmsg.Text = "您不能删除 " + markingprdname + ".其他  印记  期  是  创立  根据  它.";
                                break;
                            case "ja-JP":
                                lblmsg.Text = "あなたが削除することはできません " + markingprdname + ".その他のマークの下で発見された期間.";
                                break;
                            case "de-DE":
                                lblmsg.Text = "Sie können nicht gelöscht " + markingprdname + ".Andere Markierung Zeiten waren gefunden unter es.";
                                break;
                            case "ko-KR":
                                lblmsg.Text = "당신은 삭제할 수없습니다   " + markingprdname + ".기타 마킹 기간 그 아래를 발견했다.";
                                break;
                            case "fr-FR":
                                lblmsg.Text = "Vous ne pouvez pas supprimer " + markingprdname + ".Autres périodes de marquage ont été trouvés à ce titre.";
                                break;
                            case "it-IT":
                                lblmsg.Text = "Non è possibile eliminare  " + markingprdname + ".Altri periodi di marcatura sono stati trovati sotto di essa.";
                                break;
                            case "ru-RU":
                                lblmsg.Text = "Вы не можете удалить " + markingprdname + ".Другая маркировка периоды были найдены в соответствии с ней.";
                                break;
                            case "pt-BR":
                                lblmsg.Text = "Você não pode apagar " + markingprdname + ".Outros marcação períodos em que foram encontrados.";
                                break;
                            case "ar-SA":
                                lblmsg.Text = ".العلامات فترات أخرى تم العثور عليها في إطار." + markingprdname + "لا يمكنك حذف ";
                                break;
                        }
                        ModalPopupExtender3.Enabled = true;
                        ModalPopupExtender3.Show();
                    }
                    PopulateFullYear();
                }
                MPBL.Close();
            }
            catch (Exception ex)
            {
            }
        }

        protected void gvLevel2_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
                if (e.CommandName == "EditQuarterRecords")
                {
                    ModalPopupExtender2.Enabled = true;
                    ModalPopupExtender2.Show();
                    OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
                    SISInstall SISInstall = new SISInstall();
                    DataTable dtDateFormat = InstallBL.getdateformat();
                    if (dtDateFormat.Rows.Count > 0)
                    {
                        SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
                    }
                    string info = e.CommandArgument.ToString();
                    string[] arg = new string[2];
                    char[] splitter = { '_' };
                    arg = info.Split(splitter);
                    string markingperiodid = arg[0];
                    string SchyrId = arg[1];
                    hdnMarkingPeriodId.Value = markingperiodid;
                    hdnschyrid.Value = SchyrId;
                    int SchId = Convert.ToInt32(Session["SchoolID"]);
                    int MarkingPeriodId = Convert.ToInt32(markingperiodid);
                    int SchyrIds = Convert.ToInt32(SchyrId);
                    string MarkingPeriodType = "Q";
                    DataTable dt = MPBL.Populatemarkingperiodforedit(MarkingPeriodId);
                    txtTitleEdit.Text = dt.Rows[0]["sch_mp_name"].ToString();
                    txtShortNameEdit.Text = dt.Rows[0]["sch_mp_short_nm"].ToString();
                    if (dt.Rows[0]["sch_mp_grading_ind"].ToString() == "Y")
                    {
                        chkGradeEdit.Checked = true;
                    }
                    else
                    {
                        chkGradeEdit.Checked = false;
                    }
                    string sch_mp_start_date = (dt.Rows[0]["sch_mp_start_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpstartdate = Convert.ToDateTime(sch_mp_start_date);
                    txtBeginsEdit.Text = schmpstartdate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_end_date = (dt.Rows[0]["sch_mp_end_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpenddate = Convert.ToDateTime(sch_mp_end_date);
                    txtEndsEdit.Text = schmpenddate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_grd_start_date = (dt.Rows[0]["sch_mp_grd_start_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpgrdstartdate = Convert.ToDateTime(sch_mp_grd_start_date);
                    txtGPBeginsEdit.Text = schmpgrdstartdate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_grd_end_date = (dt.Rows[0]["sch_mp_grd_end_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpgrdenddate = Convert.ToDateTime(sch_mp_grd_end_date);
                    txtGPEndsEdit.Text = schmpgrdenddate.ToString(SISInstall.CalenderDateFormat);
                    InstallBL.Close();
                }
                if (e.CommandName == "AddPeriod")
                {
                    ModalPopupExtender1.Enabled = true;
                    ModalPopupExtender1.Show();
                    string schyrid = e.CommandArgument.ToString();
                    hdnschyrid.Value = schyrid;
                    hdnParentType.Value = "Q";
                }
                if (e.CommandName == "DeleteQuarter")
                {
                    string info = e.CommandArgument.ToString();
                    string[] arg = new string[2];
                    char[] splitter = { '_' };
                    arg = info.Split(splitter);
                    string markingperiodid = arg[0];
                    string SchyrId = arg[1];
                    string markingprdname = arg[2];
                    int MarkingPeriodId = Convert.ToInt32(markingperiodid);
                    int SchyrIds = Convert.ToInt32(SchyrId);
                    DataTable dt = MPBL.getchildcount(SchyrIds);
                    if (dt.Rows.Count == 0)
                    {
                        MPBL.DeleteMarkingPeriod(MarkingPeriodId, SchyrIds);
                    }
                    else
                    {
                        string s = System.Web.HttpContext.Current.Session["MLCulture"].ToString();
                        switch (s)
                        {
                            case "en-US":
                                lblmsg.Text = "You cannot delete " + markingprdname + ".Other marking periods were found under it.";
                                break;
                            case "es-MX":
                                lblmsg.Text = "No se puede eliminar " + markingprdname + ".Otro marcado en los períodos que se encontraron bajo.";
                                break;
                            case "zh-CN":
                                lblmsg.Text = "您不能删除 " + markingprdname + ".其他  印记  期  是  创立  根据  它.";
                                break;
                            case "ja-JP":
                                lblmsg.Text = "あなたが削除することはできません " + markingprdname + ".その他のマークの下で発見された期間.";
                                break;
                            case "de-DE":
                                lblmsg.Text = "Sie können nicht gelöscht " + markingprdname + ".Andere Markierung Zeiten waren gefunden unter es.";
                                break;
                            case "ko-KR":
                                lblmsg.Text = "당신은 삭제할 수없습니다   " + markingprdname + ".기타 마킹 기간 그 아래를 발견했다.";
                                break;
                            case "fr-FR":
                                lblmsg.Text = "Vous ne pouvez pas supprimer " + markingprdname + ".Autres périodes de marquage ont été trouvés à ce titre.";
                                break;
                            case "it-IT":
                                lblmsg.Text = "Non è possibile eliminare  " + markingprdname + ".Altri periodi di marcatura sono stati trovati sotto di essa.";
                                break;
                            case "ru-RU":
                                lblmsg.Text = "Вы не можете удалить " + markingprdname + ".Другая маркировка периоды были найдены в соответствии с ней.";
                                break;
                            case "pt-BR":
                                lblmsg.Text = "Você não pode apagar " + markingprdname + ".Outros marcação períodos em que foram encontrados.";
                                break;
                            case "ar-SA":
                                lblmsg.Text = ".العلامات فترات أخرى تم العثور عليها في إطار." + markingprdname + "لا يمكنك حذف ";
                                break;
                        }
                        ModalPopupExtender3.Enabled = true;
                        ModalPopupExtender3.Show();
                    }
                    PopulateFullYear();
                }
                MPBL.Close();
            }
            catch 
            { 
            }
        }

        protected void gvLevel3_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                OpenSISServiceMarkingPeriodClient MPBL = new OpenSISServiceMarkingPeriodClient();
                if (e.CommandName == "EditPeriodRecord")
                {
                    ModalPopupExtender2.Enabled = true;
                    ModalPopupExtender2.Show();
                    OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
                    SISInstall SISInstall = new SISInstall();
                    DataTable dtDateFormat = InstallBL.getdateformat();
                    if (dtDateFormat.Rows.Count > 0)
                    {
                        SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
                    }
                    string info = e.CommandArgument.ToString();
                    string[] arg = new string[2];
                    char[] splitter = { '_' };
                    arg = info.Split(splitter);
                    string markingperiodid = arg[0];
                    string SchyrId = arg[1];
                    hdnMarkingPeriodId.Value = markingperiodid;
                    hdnschyrid.Value = SchyrId;
                    int SchId = Convert.ToInt32(Session["SchoolID"]);
                    int MarkingPeriodId = Convert.ToInt32(markingperiodid);
                    int SchyrIds = Convert.ToInt32(SchyrId);
                    string MarkingPeriodType = "P";                    
                    DataTable dt = MPBL.Populatemarkingperiodforedit(MarkingPeriodId);
                    txtTitleEdit.Text = dt.Rows[0]["sch_mp_name"].ToString();
                    txtShortNameEdit.Text = dt.Rows[0]["sch_mp_short_nm"].ToString();
                    if (dt.Rows[0]["sch_mp_grading_ind"].ToString() == "Y")
                    {
                        chkGradeEdit.Checked = true;
                    }
                    else
                    {
                        chkGradeEdit.Checked = false;
                    }
                    string sch_mp_start_date = (dt.Rows[0]["sch_mp_start_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpstartdate = Convert.ToDateTime(sch_mp_start_date);
                    txtBeginsEdit.Text = schmpstartdate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_end_date = (dt.Rows[0]["sch_mp_end_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpenddate = Convert.ToDateTime(sch_mp_end_date);
                    txtEndsEdit.Text = schmpenddate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_grd_start_date = (dt.Rows[0]["sch_mp_grd_start_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpgrdstartdate = Convert.ToDateTime(sch_mp_grd_start_date);
                    txtGPBeginsEdit.Text = schmpgrdstartdate.ToString(SISInstall.CalenderDateFormat);
                    string sch_mp_grd_end_date = (dt.Rows[0]["sch_mp_grd_end_date"].ToString().Split(" ".ToCharArray())[0]);
                    DateTime schmpgrdenddate = Convert.ToDateTime(sch_mp_grd_end_date);
                    txtGPEndsEdit.Text = schmpgrdenddate.ToString(SISInstall.CalenderDateFormat);
                    InstallBL.Close();
                }
                if (e.CommandName == "DeletePeriod")
                {
                    string info = e.CommandArgument.ToString();
                    string[] arg = new string[2];
                    char[] splitter = { '_' };
                    arg = info.Split(splitter);
                    string markingperiodid = arg[0];
                    string SchyrId = arg[1];
                    int MarkingPeriodId = Convert.ToInt32(markingperiodid);
                    int SchyrIds = Convert.ToInt32(SchyrId);
                    MPBL.DeleteMarkingPeriod(MarkingPeriodId, SchyrIds);
                    PopulateFullYear();
                }
            }
            catch 
            { 
            }
        }

        protected void btnAddCancel_Click(object sender, EventArgs e)
        {
            try
            {
                Function fn = new Function();
                txtTitle.Text = "";
                txtShortName.Text = "";
                chkGrade.Checked = false;
                txtBegins.Text = "";
                txtEnds.Text = "";
                txtGPBegins.Text = "";
                txtGPEnds.Text = "";
            }
            catch 
            { 
            }
        }

        //private void ml_InitCulture()
        //{
        //    if (Session["MLCulture"] != null && Session["MLUICulture"] != null)
        //    {

        //        String MLCultureName = (String)Session["MLCulture"];
        //        String MLUICultureName = (String)Session["MLUICulture"];
        //        sCulture = Session["MLCulture"].ToString();
        //        if ((MLCultureName != null) && (MLCultureName.Length > 0))
        //        {
        //            Page.Culture = MLCultureName;
        //        }
        //        if ((MLUICultureName != null) && (MLUICultureName.Length > 0))
        //        {
        //            Page.UICulture = MLUICultureName;
        //        }
        //    }
        //}

        //protected override void InitializeCulture()
        //{
        //    ml_InitCulture();
        //}

    }